import { fileURLToPath, URL } from 'node:url'
import { createPlugins } from './config/plugins'
import { defineConfig } from 'vite'

import { createProxy } from './config/proxy'
import { ConfigEnv } from 'vite'
import * as dotenv from 'dotenv'
import { createBuild } from './config/build'
// import postcsspxtoviewport from 'postcss-px-to-viewport'

// const mapToken = defaultAlgorithm(defaultSeed);

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }: ConfigEnv) => {
  // 当前环境变量
  const env: any = dotenv.config({ path: `./.env.${mode}` }).parsed

  return {
    server: {
      port: 9003,
      proxy: createProxy(env),
    },
    build: createBuild(mode),
    plugins: createPlugins(mode),
    resolve: {
      extensions: ['.vue', '.ts', '.js', 'tsx', 'jsx'],
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    }
  }
})
